<?php

namespace App\Filament\Resources\CustomerResource\Pages;

use App\Filament\Resources\CustomerResource;
use App\Models\Customer;
use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Enums\IconPosition;
use Illuminate\Database\Eloquent\Builder;

class ListCustomers extends ListRecords
{
    protected static string $resource = CustomerResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\CreateAction::make(),
        ];
    }

    public function getTabs(): array
    {
        return [
            'all' => Tab::make()->label('全部')->icon('heroicon-m-user-group')->iconPosition(IconPosition::Before),
            'active' => Tab::make()->label('启用')
                ->modifyQueryUsing(fn(Builder $query) => $query->where('active', 1))
                ->badge(Customer::query()->where('active', 1)->count() . '条')
                ->badgeColor('success'),
            'inactive' => Tab::make()->label('禁用')->modifyQueryUsing(fn(Builder $query) => $query->where('active', 0)),
        ];
    }

    public function getDefaultActiveTab(): string|int|null
    {
        return 'active';
    }
}
